import unittest
from Common.selenium_tools import get_browser
from Business.用户名中心.登录 import login


class Login_Test(unittest.TestCase):
    """
    1、打开浏览器
    2、打开首页
    3、点击请登录
    4、输入账号
    5、输入密码
    6、点击立即登录
    7、断言
    8、关闭浏览器
    """

    def setUp(self):
        self.driver = get_browser()

    def tearDown(self):
        self.driver.quit()

    def test_Login_1(self):
        username = "liu01"
        password = "123456"

        login(self.driver, username, password)

        # 断言
        text = self.driver.find_element_by_xpath('//*[@class="box_1"]//p[1]').text
        self.assertEqual("登录成功", text)
        text = self.driver.find_element_by_xpath('//*[@class="f4_b"]').text
        self.assertEqual(username, text)

    def test_Login_2(self):
        username = "liu01"
        password = "123456789"

        login(self.driver, username, password)

        # 断言
        text = self.driver.find_element_by_xpath('//*[@class="box_1"]//p[1]').text
        self.assertEqual("用户名或密码错误", text)

    def test_Login_3(self):
        username = ""
        password = ""

        login(self.driver, username, password)

        # 断言
        text = self.driver.switch_to.alert.text
        self.assertIn('用户名不能为空', text)
        self.assertIn('登录密码不能为空', text)

    def test_Login_4(self):
        username = "liu01"
        password = ""

        login(self.driver, username, password)

        # 断言
        text = self.driver.switch_to.alert.text
        self.assertIn('登录密码不能为空', text)

    def test_Login_5(self):
        username = ""
        password = "123456"

        login(self.driver, username, password)

        # 断言
        text = self.driver.switch_to.alert.text
        self.assertIn('用户名不能为空', text)
